/**
 * @author SaoE
 * @date 2025/2/21 11:04
 */
public class _543 {
    int res = 0;
    public int diameterOfBinaryTree(TreeNode root) {
        maxHeight(root);
        return res;
    }
    public int maxHeight(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int left = maxHeight(root.left);
        int right = maxHeight(root.right);
        res = Math.max(res, left + right);
        return Math.max(left, right) + 1;
    }
}
